import random
import string
import allure


from base_layer import BasePage
from airtest.core.api import Template


#登录页面元素及操作
class LoginPage(BasePage):

    def __init__(self):
        super().__init__()

        #商户输入框
        self.title_link = Template(r"D:\AIRtest\UDun_UI\index\153328.png")
        # 选择商户按钮
        self.merchant_select_btn = Template(r"D:\AIRtest\UDun_UI\index\154039.png")
        # 选择登录邮箱
        self.account_select_area = Template(r"D:\AIRtest\UDun_UI\index\tpl1760345484680.png",record_pos=(0.278, -0.0),resolution=(1311, 823))
        #登录按钮
        self.password_input_area = Template(r"D:\AIRtest\UDun_UI\index\tpl1760343437338.png",record_pos=(0.293, 0.096),resolution=(1311, 823))
        # # 个人头像
        # self.login_btn = Template(r"D:\AIRtest\UDun_UI\index\tpl1760346015429.png",record_pos=(-0.47, 0.331),resolution=(1136, 823))

    def open_login_page(self,account_Merchant : str):
        #点击商户号输入框
        self.touch_element(self.title_link, desc="标题链接窗口")
        # 输入商户号
        self.input_text(account_Merchant,  desc="输入商户号")
        # 点击选择商户按钮
        self.touch_element(self.merchant_select_btn, desc="选择商户")

    def enter_email(self,account_email : str):
        #输入登录邮箱
        self.input_text(account_email, desc="输入登录邮箱")
        #选择登录邮箱
        self.touch_element(self.account_select_area, desc="选择登录邮箱")

    def enter_password(self,account_password : str):
        #输入密码
        self.input_text(account_password, desc="输入登录密码")

    def enter_login(self):
        #点击登录
        self.touch_element(self.password_input_area, desc="点击密码输入区域")


#个人中心页面元素及操作
class PersonalPage(BasePage):

    def __init__(self):
        super().__init__()
        # 个人界面入口
        self.personal_entry = Template(r"D:\AIRtest\UDun_UI\index\tpl1760346015429.png",record_pos=(-0.47, 0.331),resolution=(1136, 823))
        # 退出登录按钮
        self.logout_btn = Template(r"D:\AIRtest\UDun_UI\index\tpl1760346026127.png",record_pos=(-0.184, 0.243),resolution=(1136, 823))
    def go_to_personal(self):
        """进入个人界面"""
        self.touch_element(self.personal_entry, desc="进入个人界面")
    def logout(self):
        """退出登录"""
        self.touch_element(self.logout_btn, desc="点击退出登录")

#创建钱包页面元素及操作
class CreateWalletPage(BasePage):

    def __init__(self):
        super().__init__()
        # 钱包页面入口
        self.wallet_entry = Template(r"D:\AIRtest\UDun_UI\index\134957.png",record_pos=(0.278, -0.0),resolution=(1311, 823))
        #创建钱包按钮
        self.create_wallet_btn = Template(r"D:\AIRtest\UDun_UI\index\135109.png",record_pos=(0.293, 0.096),resolution=(1311, 823))
        #钱包名称输入框
        self.wallet_name_input = Template(r"D:\AIRtest\UDun_UI\index\135251.png")


    def Create_wallet(self,wallet_name = None):

        self.touch_element(self.wallet_entry, desc="进入钱包界面")
        self.touch_element(self.create_wallet_btn, desc="点击创建钱包")
        self.touch_element(self.wallet_name_input, desc="点击钱包名称输入框")
        if wallet_name is None:
            wallet_name = self.random_name(10)
        self.input_text(wallet_name, desc="输入钱包名称")

# 交易页面元素及操作
class TransactionPage(BasePage):

    def __init__(self):
        super().__init__()
        #钱包页面入口
        self.wallst_entry = Template(r"D:\AIRtest\UDun_UI\index\134957.png",record_pos=(0.278, -0.0),resolution=(1311, 823))
        #发送按钮
        self.send_btn = Template(r"D:\AIRtest\UDun_UI\index\145622.png")
        #选择币种
        self.coin_select_area = Template(r"D:\AIRtest\UDun_UI\index\145902.png")
        #接收方地址
        self.receive_address_input = Template(r"D:\AIRtest\UDun_UI\index\150004.png")
        #选择地址
        self.address_select_area = Template(r"D:\AIRtest\UDun_UI\index\150201.png")
        #金额输入框
        self.amount_input = Template(r"D:\AIRtest\UDun_UI\index\150500.png")
        #备注输入框
        self.remark_input = Template(r"D:\AIRtest\UDun_UI\index\150604.png")
        #提交按钮
        self.confirm_btn = Template(r"D:\AIRtest\UDun_UI\index\150847.png")
        #发送按钮
        self.forword_btn = Template(r"D:\AIRtest\UDun_UI\index\151025.png")
        #交易密码输入框
        self.password_btn = Template(r"D:\AIRtest\UDun_UI\index\151214.png")
        #交易密码确认按钮
        self.password_confirm_btn = Template(r"D:\AIRtest\UDun_UI\index\151407.png")
        #google验证码输入框
        self.google_code_input = Template(r"D:\AIRtest\UDun_UI\index\151456.png")

    def send_coin(self,receive_address = "3Dj3UuHT1B1wrKLoZBijneTqwRv1o23q6E",amount = "1" ,remark = "1",password = "Asdfghjkl",google_code = None):

        self.touch_element(self.wallst_entry, desc="进入钱包界面")
        self.touch_element(self.send_btn, desc="进入发送界面")
        self.touch_element(self.coin_select_area, desc="选择币种BTC")
        self.touch_element(self.receive_address_input, desc="点击接收方地址输入框")
        self.input_text(receive_address, desc="输入接收方地址")
        self.touch_element(self.address_select_area, desc="选择接收方地址")
        self.touch_element(self.amount_input, desc="点击金额输入框")
        self.input_text(amount, desc="输入金额")
        self.touch_element(self.remark_input, desc="点击备注输入框")
        self.input_text(remark, desc="输入备注")
        self.touch_element(self.confirm_btn, desc="点击提交按钮")
        self.touch_element(self.forword_btn, desc="点击发送按钮")
        self.touch_element(self.password_btn, desc="点击交易密码输入框")
        self.input_text(password, desc="输入交易密码")
        self.touch_element(self.password_confirm_btn, desc="点击确认按钮")
        self.touch_element(self.google_code_input, desc="点击google验证码输入框")
        if google_code is None:
            google_code = self.GetGoogleCode()
        self.input_text(google_code, desc="输入google验证码")
        # self.GoogleAuthFailed(google_code, retry_times=3)


# 创建地址页面元素及操作
class AddressPage(BasePage):

    def __init__(self):
        super().__init__()

    def create_address(self):
        pass
